package com.kimu.product_service_provider.service;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kimu.product_service_interface.entity.Product;
import com.kimu.product_service_interface.mapper.ProductMapper;
import com.kimu.product_service_interface.service.ProductService;
import org.apache.dubbo.config.annotation.DubboService;

@DubboService
public class ProductServiceImpl implements ProductService {

    private ProductMapper productMapper;

    public ProductServiceImpl(ProductMapper productMapper) {
        this.productMapper = productMapper;
    }

    @Override
    public int createProduct(Product product) {
        int row = productMapper.insert(product);
        return row;
    }

    @Override
    public Product getProductById(Long id) {
        Product product = productMapper.selectById(id);
        return product;
    }

    @Override
    public int updateProduct(Product product) {
        int row = productMapper.updateById(product);
        return row;
    }

    @Override
    public int deleteProductById(Long id) {
        int row = productMapper.deleteById(id);
        return row;
    }

    @Override
    public List<Product> getProductsByAI(String keyword) {
        // TODO Auto-generated method stub
        throw new UnsupportedOperationException("Unimplemented method 'getProductsByAI'");
    }

    @Override
    public IPage<Product> getProducts(Page<Product> page) {
        IPage<Product> result = productMapper.selectProductPage(page, null, null, null);
        return result;
    }

    @Override
    public Map<String, Object> getProductCascade(Long id) {
        return null;
    }

}
